using System;
using System.ComponentModel;
using System.Collections.Generic;

namespace needle.Services.astra.Collections
{
	/// <summary>
	/// Interface for list supporting paging of items.
	/// </summary>
	/// <remarks>
	/// <see cref="INotifyPropertyChanged.PropertyChanged"/> is fired when
	///		<see cref="Page"/> or
	///		<see cref="PageUI"/> or
	///		<see cref="PageSize"/> or
	///		<see cref="PageCount"/> or
	///		<see cref="PageStartIndex"/> or
	///		<see cref="PageEndIndex"/>
	/// is changed.
	/// </remarks>
	/// <typeparam name="T">List item type.</typeparam>
	public interface IPagingList<T> : IPaging, IList<T>
	{
		/// <summary>
		/// Global index of first item on <see cref="Page"/>.
		/// </summary>
		int PageStartIndex
		{
			get;
		}
		/// <summary>
		/// Global index of last item on <see cref="Page"/>.
		/// </summary>
		int PageEndIndex
		{
			get;
		}

		/// <summary>
		/// Changes <see cref="Page"/> if needed.
		/// </summary>
		/// <param name="globalIndex">Global index specifying page on which it resides.</param>
		void GoToPageOfIndex(int globalIndex);
		/// <summary>
		/// Changes <see cref="Page"/> if needed.
		/// </summary>
		/// <param name="item">Item specifying page on which it resides.</param>
		void GoToPageOfItem(T item);
		/// <summary>
		/// Translates <paramref name="index"/> from global index to index on page or vice versa.
		/// </summary>
		/// <remarks>It does not check <paramref name="index"/> validity.</remarks>
		/// <param name="index">Index.</param>
		/// <param name="fromPageSubset">
		/// If true, <paramref name="index"/> is page one and returned is global one.
		/// If false, <paramref name="index"/> is global one and returned is page one.
		/// </param>
		/// <returns>Translated index.</returns>
		int TranslateIndex(int index, bool fromPageSubset);
		/// <summary>
		/// Gets <see cref="Page"/> on which specified index of item resides.
		/// </summary>
		/// <param name="globalIndex">Global index.</param>
		/// <returns>Found page, otherwise -1.</returns>
		int GetPageOfIndex(int globalIndex);
		/// <summary>
		/// Validates index on current <see cref="Page"/>.
		/// </summary>
		/// <param name="globalIndex">Global index.</param>
		/// <returns>true, if <paramref name="globalIndex"/> is valid.</returns>
		bool IsValidPageIndex(int globalIndex);
	}
}
